package com.anolesoft.amljmes.billing.service.mapper;

import cn.hutool.core.util.StrUtil;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.amljmes.billing.controller.WorkshopInfoController;
import com.anolesoft.amljmes.billing.dto.WorkshopInfoDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;
import java.util.Map;

@Mapper
public interface WorkshopInfoServiceMapper {
    @SelectProvider(type=createSQL.class, method = "queryWorkshopSQL")
    List<WorkshopInfoDto> queryWorkshopSQL(WorkshopInfoController.DemoVO demoVO);
    public static class createSQL {
        public static String queryWorkshopSQL(WorkshopInfoController.DemoVO demoVO){
            return new SQL(){
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" a.id as key,a.id, a.cjr, a.cjsj, a.xgr, a.xgsj, a.factory_id, a.workshop_name,0 as pageNo,10 as pageSize  from jcwh_stk_workshop a where 1=1 ");
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getWorkshopName())){
                        String workshopName = demoVO.getWorkshopName();
                        sql.append(" and upper(a.workshop_name) = upper(#{workshopName, jdbcType=VARCHAR})");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getFactoryId())){
                        String factoryId = demoVO.getWorkshopName();
                        sql.append(" and upper(a.factory_id) = upper(#{factoryId, jdbcType=VARCHAR})");
                    }
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }

    @Insert("    insert into jcwh_stk_workshop" +
            "      (id,cjr, factory_id, workshop_name)" +
            "    values" +
            "      (sys_guid(),#{cjr, jdbcType=VARCHAR}, #{factoryId, jdbcType=VARCHAR}, #{workshopName, jdbcType=VARCHAR})"
    )
    int addWorkshop(WorkshopInfoDto inFoDtoParam);

    @Update("    update jcwh_stk_workshop" +
            "      set xgr = #{xgr, jdbcType=VARCHAR},xgsj = sysdate,workshop_name = #{workshopName, jdbcType=VARCHAR}" +
            "    where id = #{id, jdbcType=VARCHAR}"
    )
    int updateWorkshop(WorkshopInfoDto inFoDtoParam);

    @Delete("delete from jcwh_stk_workshop where id = #{id, jdbcType=VARCHAR} ")
    int deleteWorkshop(WorkshopInfoDto inFoDtoParam);

    @Select(" select count(1) from jcwh_stk_workshop where workshop_name = #{workshopName, jdbcType = VARCHAR} and factory_id = #{factoryId, jdbcType = VARCHAR} ")
    int isWorkshopName(WorkshopInfoDto inFoDtoParam);

    @Select("select * from jcwh_stk_workshop")
    List<WorkshopInfoDto> WorkshopAll();
}
